package net.jiastudy.web.rest.controller.sys;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.jiastudy.biz.datasync.DataSyncService;
import net.jiastudy.biz.datasync.SyncUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/datasync")
@Api(value = "DataSyncController  数据同步")
public class DataSyncController {
    @Resource
    private DataSyncService dataSyncService;
    @Value("${sync.operate}")
    private Boolean syncOperate;

    @ApiOperation(value = "信息同步", notes = "")
    @RequestMapping(path = "/all", method = RequestMethod.POST)
    public boolean studentSync() {
        return dataSyncService.syncAll();
    }

    @ApiOperation(value = "同步状态信息", notes = "")
    @RequestMapping(path = "/info", method = RequestMethod.GET)
    public Map<String, Object> getInfo() {
        Map<String, Object> map = new HashMap<>();
        map.put("canSync", this.syncOperate);
        if (SyncUtil.getTeacherSyncBatchCount() > 0){
            map.put("isSync", true);
        } else {
            map.put("isSync", false);
        }

        return map;
    }
}
